﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using GameControls;

namespace ThouShaltNotBrick.Logic.GameStates
{
    internal sealed class MainMenuGameState : GameStateBase
    {
        #region Constants
        #endregion

        #region Properties
        private Button mPlayButton;
        private Button mExitButton;
        #endregion

        #region Events
        #endregion

        #region Constructors
        #endregion

        #region Overriden Methods
        protected override void InitializeImpl()
        {
            mClearColor = Color.Blue;

            InitializeControls();
        }

        protected override void DestroyImpl()
        {
            DestroyControls();
        }

        protected override void StartImpl(GameStateChangeData pChangeData)
        {
        }

        protected override void StopImpl()
        {
        }

        protected override void ResumeImpl(GameStateChangeData pChangeData)
        {
        }

        protected override void PauseImpl()
        {
        }

        protected override void HandleInputImpl(GameTime pGameTime)
        {
            //if (InputManager.IsJustPressed(Keys.Escape) ||
            //    InputManager.IsJustPressed(Keys.Enter) ||
            //    InputManager.IsJustPressed(MouseButton.Left) ||
            //    InputManager.IsJustPressed(MouseButton.Right))
            //{
            //    GameStateManager.ChangeState(GameStateType.SelectCampaign);
            //}
        }

        protected override void UpdateImpl(GameTime pGameTime)
        {
        }

        protected override void DrawImpl(GameTime pGameTime)
        {
        }
        #endregion

        #region Methods
        private void InitializeControls()
        {
            DestroyControls();

            Rectangle playButtonRect = new Rectangle(100, 100, 100, 100);
            mPlayButton = new Button(playButtonRect, mGraphicsResources.MenuButtonTexture);
            mPlayButton.Label.SetText("PLAY", mFontResources.Font28, Color.Orange);
            mPlayButton.Pressed += PlayButtonPressedHandler;
            mControls.Add(mPlayButton);

            Rectangle exitButtonRect = new Rectangle(300, 100, 200, 200);
            mExitButton = new Button(exitButtonRect, mGraphicsResources.MenuButtonTexture);
            mExitButton.Label.SetText("EXIT", mFontResources.Font28, Color.Orange);
            mExitButton.Pressed += ExitButtonPressedHandler;
            mControls.Add(mExitButton);

            Rectangle creditsButtonRect = new Rectangle(100, 400, 300, 100);
            Button creditsButton = new Button(creditsButtonRect, mGraphicsResources.MenuButtonTexture);
            creditsButton.Label.SetText("CREDITS", mFontResources.Font28, Color.Orange);
            mControls.Add(creditsButton);
        }

        private void DestroyControls()
        {
            if (mPlayButton != null)
            {
                mPlayButton.Pressed -= PlayButtonPressedHandler;
            }
            if (mExitButton != null)
            {
                mExitButton.Pressed -= ExitButtonPressedHandler;
            }

            mControls.Clear();
        }
        #endregion

        #region Event Handlers
        private void PlayButtonPressedHandler(object sender, EventArgs e)
        {
            GameStateManager.PushState(GameStateType.SelectCampaign);
        }

        private void ExitButtonPressedHandler(object sender, EventArgs e)
        {
            mGameManager.ExitGame();
        }
        #endregion

        #region Inner Classes
        #endregion
    }
}